Function Reference

_AD_GetAccountsExpired

Returns an array with FQDNs of expired accounts (user, computer).

#Include <AD.au3>
_AD_GetAccountsExpired([$sClass = "user"[ ,$sDTEExpire = ""[ ,$sDTSExpire = ""[, $sRoot = ""]]]])

 

Parameters

$sClass Optional: Specifies if expired user accounts or computer accounts should be returned (default = "user").
"user" - Returns objects of category "user"
"computer" - Returns objects of category "computer"
$sDTEExpire YYYY/MM/DD HH:MM:SS (local time) returns all accounts that expire between $sDTSExpire and the specified date/time (default = "" = Now)
$sDTSExpire YYYY/MM/DD HH:MM:SS (local time) returns all accounts that expire between the specified date/time and $sDTEExpire (default = "1601/01/01 00:00:00)
$sRoot Optional: FQDN of the OU where the search should start (default = "" = search the whole tree)

 

Return Value

Success: One-based two dimensional array of FQDNs of expired accounts
    0 - FQDNs of expired accounts
    1 - account expired YYYY/MM/DD HH:NMM:SS UTC
    2 - account expired YYYY/MM/DD HH:NMM:SS local time of calling user
Failure: "", sets @error to:
    1 - No expired accounts found. @extended is set to the error returned by LDAP
    2 - Specified date/time is invalid
    3 - Invalid value for $sClass. Has to be "user" or "computer"
    4 - Specified $sRoot does not exist

 

Remarks

None.

 

Related

_AD_IsAccountExpired, _AD_SetAccountExpire

 

Example


#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#include <AD.au3>

; Open Connection to the Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

Global $aExpired[1]
; *****************************************************************************
; Example 1
; Get a list of expired user accounts
; *****************************************************************************
$aExpired = _AD_GetAccountsExpired()
If @error > 0 Then
    MsgBox(64, "Active Directory Functions - Example 1", "No expired user accounts could be found")
Else
    _ArrayDisplay($aExpired, "Active Directory Functions - Example 1 - Expired User Accounts")
EndIf

; *****************************************************************************
; Example 2
; Get a list of user accounts that expire end of this year
; *****************************************************************************
$aExpired = _AD_GetAccountsExpired("user", @YEAR & "/12/31")
If @error = 0 Then
    _ArrayDisplay($aExpired, "Active Directory Functions - Example 2 - Expired User Accounts (by the end of this year)")
ElseIf @error = 1 Then
    MsgBox(64, "Active Directory Functions - Example 2", "No expired user accounts could be found")
Else
    MsgBox(64, "Active Directory Functions - Example 2", "Invalid parameters provided")
EndIf

; *****************************************************************************
; Example 3
; Get a list of user accounts that expire between january and october this year
; *****************************************************************************
$aExpired = _AD_GetAccountsExpired("user", @YEAR & "/10/31", @YEAR & "/01/01")
If @error = 0 Then
    _ArrayDisplay($aExpired, "Active Directory Functions - Example 3 - Expired User Accounts (january to october this year)")
ElseIf @error = 1 Then
    MsgBox(64, "Active Directory Functions - Example 3", "No expired user accounts could be found")
Else
    MsgBox(64, "Active Directory Functions - Example 3", "Invalid parameters provided")
EndIf

; *****************************************************************************
; Example 4
; Get a list of expired computer accounts
; *****************************************************************************
$aExpired = _AD_GetAccountsExpired("computer")
If @error > 0 Then
    MsgBox(64, "Active Directory Functions - Example 4", "No expired computer accounts could be found")
Else
    _ArrayDisplay($aExpired, "Active Directory Functions - Example 4 - Expired Computer Accounts")
EndIf

; Close Connection to the Active Directory
_AD_Close()